import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SQLiteDatabase {
	private Connection connection = null;
	
   	public Statement connect(String dbname) throws ClassNotFoundException, SQLException {
   		if(connection != null) throw new RuntimeException("Database locked, cannot connect");
   		
   		Class.forName("org.sqlite.JDBC");
   		
	    //Create connection
	    Statement statement = null;
	    try {
	      // create a database connection
	      connection = DriverManager.getConnection("jdbc:sqlite:"+dbname+".db");
	      statement = connection.createStatement();
	      statement.setQueryTimeout(30);
	    }
	    
	    catch(SQLException e) {
	    	closeDatabase();
	    	throw e;
	    }
	    
	    return statement;
   	}
   	
   	public ResultSet queryClose(Statement s) {
   		ResultSet rs = null;
   		
   		return rs;
   	}
   	
   	public void closeDatabase() {
    	try {
    		if(connection != null) connection.close();
    	}
    	catch(SQLException e) {
    		// connection close failed.
    		System.err.println(e);
    	}
    	connection = null;
   	}
}
